﻿using System;
using System.Data;
using WebUI.Lang;
using System.IO;
using WebUI.Models;

namespace WebUI
{
    public partial class Main : AdlerBasePage
    {
        public string displayshow = "";
        public string displaylink = "";
        public string displayimg = "";
        public string displayName = "";
        public string collection = "";
        public string lookbook = "";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            WebComponent component = new WebComponent();

            string bannercollection = "~/Uploads/XML/bannerCollection.xml";
            string bannerlookbook = "~/Uploads/XML/bannerLookBook.xml";
            // Banner Look book
            using (DataSet dsmain = new DataSet())
            {
                if (!File.Exists(Server.MapPath(bannercollection))) return;
                dsmain.ReadXml(Server.MapPath(bannercollection));
                if (dsmain.Tables[0].Rows.Count > 0)
                {
                    displaylink = dsmain.Tables[0].Rows[0]["DisplayLink"].ToString();
                    displayimg = dsmain.Tables[0].Rows[0]["DisplayImg"].ToString();
                    displayName = dsmain.Tables[0].Rows[0]["DisplayName"].ToString();
                    lookbook = lookbook + component.getBannerCollection(displaylink, displayimg, displayName);
                }
            }

            // Banner Collection
            using (DataSet dsmain = new DataSet())
            {
                if (!File.Exists(Server.MapPath(bannerlookbook))) return;
                dsmain.ReadXml(Server.MapPath(bannerlookbook));
                if (dsmain.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < dsmain.Tables[0].Rows.Count; i++)
                    {
                        displayshow = dsmain.Tables[0].Rows[i]["DisplayShow"].ToString();
                        displaylink = dsmain.Tables[0].Rows[i]["DisplayLink"].ToString();
                        displayimg = dsmain.Tables[0].Rows[i]["DisplayImg"].ToString();
                        displayName = dsmain.Tables[0].Rows[i]["DisplayName"].ToString();
                        collection = collection + component.getBannerLookbook(displayshow, displaylink, displayimg, displayName);
                    }
                }
            }
        }
    }
}